const domain = "http://172.16.125.201";
// const domain ="http://172.16.183.231:80";

// 基底部门权限接口
const getDeptRequest = "/HT_DATA_EIGHT.getUserDeptCode.do";

// layout_ditor
// 135环境
// const layout_editorURL = 'http://localhost:7888/layout_editor';
const layout_editorURL = '/layout_editor';

//从URL中截取参数值
function GetQueryString(paramKey) {
    var reg = new RegExp("(^|&)" + paramKey + "=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return decodeURI(r[2]);
    return null;
}

//请求头
var request_headers = {
    "CAS_TOKEN": getToken()
};

var url = domain + "/HT_DATA_EIGHT.getGlobalStatistics.do";

function ajaxQuery(params, action) {
    $.ajax({
        type: "POST",
        url: url,
        data: params,
        headers: request_headers,
        async: true,
        // contentType: 'application/x-www-form-urlencoded',
        success: function (res) {
            var ii = JSON.parse(res);
            action(res);
        },
        error: function (error) {
            //console.log('err');
        }
    })
}

//获取token
function getToken() {
    let token;
    if (document.cookie.indexOf('cas_token') != -1) {
        token = getCookie('cas_token');
    } else if (Boolean(window.localStorage.cas_token)) {
        token = window.localStorage.cas_token;
    } else if (Boolean(GetQueryString('cas_token'))) {
        token = GetQueryString('cas_token');
    } else {
        //         $.message({
        //             message: "警告： 权限验证失败",
        //             type: 'error'
        //         });
        return null;
    }
    return token;
}

//获取cookie
function getCookie(c_name) {
    if (document.cookie.length > 0) {
        let c_start = document.cookie.indexOf(c_name + '=');
        if (c_start !== -1) {
            c_start = c_start + c_name.length + 1;
            let c_end = document.cookie.indexOf(';', c_start);
            if (c_end === -1)
                c_end = document.cookie.length;
            return unescape(document.cookie.substring(c_start, c_end));
        }
    }
    // return '';
}

let handleJson = function (k, v) {
    if (v === "true") {
        v = true;
    } else if (v === "false") {
        v = false;
    }
    return v;
};


function setConfig(frame, dialog) {
    dialog.setConfig({
        title: "机床状态明细汇总表",
        closable: true,
        draggable: true,
        // maximizable: true,
        width: 770,
        height: 625,
        borderWidth: 0,
        resizeMode: "none",
        titleBackground: "rgb(0,34,69)",
        titleColor: "rgb(255,255,255)",
        content: frame
    });
}

function setFrameStyle(frame, dialog, url) {
    var div = document.createElement('div');
    div.style.height = '800px';
    div.style.width = '1000px';
    frame.src = url;
    frame.style.height = '600px';
    frame.style.width = '800px';
    frame.style.frameborder = 'no';
    frame.style.border = "0";
    frame.style.marginwidth = "0";
    frame.style.marginheight = "0";
    frame.style.scrolling = "no";
    dialog.setModal(false);
    dialog.show();
}
function menu(caidan) {
    $(function () {
        var data =caidan
        var menu = '';
        menuFn(0, data)
        $("#app").append(menu)
        function menuFn(id, data) {
            if (data.length > 0) {
                for (var i = 0; i < data.length; i++) { //获取省一级
                    if (data[i].pid == id) {
                        menu += "<ul>"
                        menu += "<li id='zx' style='display:block'>" + '<p>' + "<a href='' class='a' style='color:#C9EFFF'>" + data[i].name + "</a>" + '&nbsp' + "<img class='b' src='up.png' style='visibility:visible'>" + "</p>" + "</br>"
                        menuFn(data[i].id, data)   //递归
                        menu += "</li>"
                        menu += "</ul>"
                    }
                }
                return menu;
            }
        }
        x = document.getElementsByClassName("a")    //地址
        for (let j = 0; j < data.length; j++) {
            x[j].href = data[j].url
        }
        y = document.getElementsByClassName("b")
        for (let k = 0; k < data.length; k++) {
            y[k].style.visibility = data[k].see  //显示
            y[k].src = data[k].img               //图片
        }
        function fn() {
            var ull = $($(this).parent().parent().children("ul"));
            if (ull.length > 0) {
                ull.toggle();
                if (ull.is(':hidden')) {    //判断状态
                    $(this).attr("src", "down.png")
                } else {
                    $(this).attr("src", "up.png")
                }
            }
        }
        $("#app").delegate("img", "click", fn)
        document.getElementById("node").addEventListener('mouseover', function () {
            all_1.s("2d.visible", false)
            all_2.s("2d.visible", true)
            document.getElementById("abc").style.display = 'block'
        });
        $(document).ready(function () {
            $("#ct").mouseleave(function () {
                all_1.s("2d.visible", true)
                all_2.s("2d.visible", false)
                document.getElementById("abc").style.display = 'none'
            });
        });
    })
}